//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;

namespace OpenLS.Vml
{
    class ShapeTypeResolver
    {
        readonly Dictionary<string, List<Action<ShapeType>>> _table = new Dictionary<string, List<Action<ShapeType>>>();
        private readonly List<ShapeType> _shapeTypes= new List<ShapeType>();

        public void AddAction (string styleId, Action<ShapeType> action)
        {
            List<Action<ShapeType>> list;
            if (!_table.TryGetValue(styleId, out list))
            {
                list = new List<Action<ShapeType>>();
                _table.Add(styleId, list);
            }
            list.Add(action);
        }

        public void AddShapeType (ShapeType style)
        {
            _shapeTypes.Add(style);
        }
        public void Resolve()
        {
            foreach (var style in _shapeTypes)
            {
                List<Action<ShapeType>> list;
                _table.TryGetValue(style.Id, out list);
                if (list != null)
                {
                    foreach (var action in list)
                    {
                        action(style);
                    }
                }
            }
        }
    }
}